from typing import Optional, List, Dict, Any
from datetime import datetime

from pydantic import BaseModel, Field


# 报表基础模型
class ReportBase(BaseModel):
    name: str
    description: Optional[str] = None
    report_type: str
    frequency: str = "once"
    parameters: Optional[Dict[str, Any]] = None
    template: Optional[str] = None


# 创建报表
class ReportCreate(ReportBase):
    project_id: Optional[int] = None


# 更新报表
class ReportUpdate(BaseModel):
    name: Optional[str] = None
    description: Optional[str] = None
    report_type: Optional[str] = None
    frequency: Optional[str] = None
    parameters: Optional[Dict[str, Any]] = None
    template: Optional[str] = None
    last_generated: Optional[datetime] = None
    next_scheduled: Optional[datetime] = None


# 报表实例基础模型
class ReportInstanceBase(BaseModel):
    file_path: str
    generation_date: datetime = Field(default_factory=datetime.utcnow)
    parameters_used: Optional[Dict[str, Any]] = None


# 创建报表实例
class ReportInstanceCreate(ReportInstanceBase):
    report_template_id: int


# API响应中的报表信息
class ReportResponse(ReportBase):
    id: int
    creator_id: int
    project_id: Optional[int] = None
    last_generated: Optional[datetime] = None
    next_scheduled: Optional[datetime] = None
    created_at: datetime
    updated_at: Optional[datetime] = None

    class Config:
        from_attributes = True


# API响应中的报表实例信息
class ReportInstanceResponse(ReportInstanceBase):
    id: int
    report_template_id: int
    generator_id: int
    created_at: datetime
    updated_at: Optional[datetime] = None

    class Config:
        from_attributes = True